package controller

import (
	"tesou.io/platform/poem-parent/poem-api/common/base"
	"tesou.io/platform/poem-parent/poem-api/common/base/pojo"
	"tesou.io/platform/poem-parent/poem-api/module/core/enums"
	"tesou.io/platform/poem-parent/poem-api/module/core/vo"
	"tesou.io/platform/poem-parent/poem-core/common/base/controller"
	"tesou.io/platform/poem-parent/poem-core/module/core/service"
)


type CommonController struct {
	controller.BaseController
	service.ListService
}


func (this *CommonController) GetTypeInfo() {
	data := &vo.ListVO{}
	page := this.GetPage()

	//仍需处理
	dataList := make([]vo.ListVO, 0)
	id := this.Input().Get("id")
	err := this.ListService.Page(data, page, &dataList,id)
	resp := new(pojo.Response)
	if nil != err {
		resp.RetCode = -1
		resp.Message = err.Error()
	} else {
		resp.Data = dataList
		resp.Page = page
	}
	this.Data["json"] = resp
	this.ServeJSON()
}


func (this *CommonController) GetType() {
	//dataOne := make([]pojo.List, 0)
	dataList := make([]*vo.ListVO, 0)
	//this.ListService.FindAll(dataList)

	//dataList := make([]*pojo.List, 0)
	this.ListService.FindAll(&dataList)

	base.Log.Info("GetType \r\n",dataList)
	resp := new(pojo.Response)
	if len(dataList)==0 {
		resp.RetCode = -1
		resp.Message = "无分类数据"
	} else {

		var mapi []interface{}
		for k, v := range enums.ListTypeMap {
			scoreMap := make(map[string]interface{}, 8)
			scoreMap["id"] = k
			scoreMap["name"] = v
			mapi = append(mapi, scoreMap)
		}
		resp.Data = mapi
	}
	this.Data["json"] = resp
	this.ServeJSON()
}
/*
func (this *CommonController) GetConfig() {
	w.Header().Add("Access-Control-Allow-Origin", "*")
	fmt.Fprintf(w, "%s", Config.MySql().Source)
}*/